package org.jeecg.modules.alarmRecording.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.alarmGroup.entity.AlarmGroup;
import org.jeecg.modules.alarmGroup.service.IAlarmGroupService;
import org.jeecg.modules.alarmRecording.entity.AlarmRecording;
import org.jeecg.modules.alarmRecording.mapper.AlarmRecordingMapper;
import org.jeecg.modules.alarmRecording.service.IAlarmRecordingService;
import org.jeecg.modules.alarmRound.service.IAlarmRoundService;
import org.jeecg.modules.alarmSettings.service.IAlarmSettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @Description: 报警记录
 * @Author: jeecg-boot
 * @Date:   2023-10-26
 * @Version: V1.0
 */
@Service
public class AlarmRecordingServiceImpl extends ServiceImpl<AlarmRecordingMapper, AlarmRecording> implements IAlarmRecordingService {

    @Autowired
    private IAlarmRoundService alarmRoundService;
    @Autowired
    private IAlarmGroupService alarmGroupService;
    @Autowired
    private IAlarmSettingsService alarmSettingsService;


    private ScheduledExecutorService executor;

    public AlarmRecordingServiceImpl() {
        executor = Executors.newSingleThreadScheduledExecutor();
    }

    @Override
    public void addRecord(String message, String point, String dept) {
        String round = alarmRoundService.selectCurrentRound();
        AlarmGroup group = alarmGroupService.getByRound(round);
        String names = group.getPeople();
        String[] split = names.split("，");
        List<String> name = Arrays.asList(split);
        alarmSettingsService.sendMessage(name, message);
        AlarmRecording alarmRecording = new AlarmRecording();
        alarmRecording.setAddress(point).setDept(dept).setMessage(message).setName(names).setHandle(0);
        baseMapper.insert(alarmRecording);
    }
}
